accurrent2 2.2.1
Loading...
Searching...
No Matches
accurrent2.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2026 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
27
28#ifndef ACCURRENT2_H
29#define ACCURRENT2_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_analog_in.h"
52#include "drv_i2c_master.h"
53
59
64
69
74#define ACCURRENT2_AC_TO_DC_V_SCALE 1.8f
75#define ACCURRENT2_SENSOR_RESOLUTION 30.0f
76
81#define ACCURRENT2_NUM_CONVERSIONS 200
82
87#define ACCURRENT2_ADC_RESOLUTION 0x0FFF
88#define ACCURRENT2_VREF_3V3 3.3
89#define ACCURRENT2_VREF_5V 5.0
90
95#define ACCURRENT2_TIMEOUT_MS 2000
96
102#define ACCURRENT2_SET_DEV_ADDR 0x4D
103 // accurrent2_set
105
110
115
120#define ACCURRENT2_MAP_MIKROBUS( cfg, mikrobus ) \
121 cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
122 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
123 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
124 // accurrent2_map // accurrent2
127
138
143typedef struct
144{
145 analog_in_t adc;
146 i2c_master_t i2c;
147
149 float vref;
151
153
158typedef struct
159{
160 pin_name_t an;
161 pin_name_t scl;
162 pin_name_t sda;
163
164 analog_in_resolution_t resolution;
165 float vref;
166
167 uint32_t i2c_speed;
168 uint8_t i2c_address;
169
171
173
184
190
201
217
232
244err_t accurrent2_read_raw_adc ( accurrent2_t *ctx, uint16_t *raw_adc );
245
257err_t accurrent2_read_voltage ( accurrent2_t *ctx, float *voltage );
258
271err_t accurrent2_read_voltage_avg ( accurrent2_t *ctx, uint16_t num_conv, float *voltage_avg );
272
284err_t accurrent2_set_vref ( accurrent2_t *ctx, float vref );
285
296err_t accurrent2_read_current ( accurrent2_t *ctx, float *current );
297
298#ifdef __cplusplus
299}
300#endif
301#endif // ACCURRENT2_H
302 // accurrent2
304
305// ------------------------------------------------------------------------ END
accurrent2_return_value_t
AC Current 2 Click return value data.
Definition accurrent2.h:179
@ ACCURRENT2_OK
Definition accurrent2.h:180
@ ACCURRENT2_ERROR
Definition accurrent2.h:181
accurrent2_drv_t
AC Current 2 Click driver selector.
Definition accurrent2.h:133
@ ACCURRENT2_DRV_SEL_I2C
Definition accurrent2.h:135
@ ACCURRENT2_DRV_SEL_ADC
Definition accurrent2.h:134
err_t accurrent2_read_current(accurrent2_t *ctx, float *current)
AC Current 2 read current function.
void accurrent2_cfg_setup(accurrent2_cfg_t *cfg)
AC Current 2 configuration object setup function.
err_t accurrent2_read_voltage(accurrent2_t *ctx, float *voltage)
AC Current 2 read voltage level function.
err_t accurrent2_set_vref(accurrent2_t *ctx, float vref)
AC Current 2 set vref function.
void accurrent2_drv_interface_sel(accurrent2_cfg_t *cfg, accurrent2_drv_t drv_sel)
AC Current 2 driver interface setup function.
err_t accurrent2_read_voltage_avg(accurrent2_t *ctx, uint16_t num_conv, float *voltage_avg)
AC Current 2 read average voltage level function.
err_t accurrent2_read_raw_adc(accurrent2_t *ctx, uint16_t *raw_adc)
AC Current 2 read raw ADC value function.
err_t accurrent2_init(accurrent2_t *ctx, accurrent2_cfg_t *cfg)
AC Current 2 initialization function.
AC Current 2 Click configuration object.
Definition accurrent2.h:159
analog_in_resolution_t resolution
Definition accurrent2.h:164
float vref
Definition accurrent2.h:165
uint32_t i2c_speed
Definition accurrent2.h:167
accurrent2_drv_t drv_sel
Definition accurrent2.h:170
pin_name_t scl
Definition accurrent2.h:161
pin_name_t sda
Definition accurrent2.h:162
pin_name_t an
Definition accurrent2.h:160
uint8_t i2c_address
Definition accurrent2.h:168
AC Current 2 Click context object.
Definition accurrent2.h:144
float vref
Definition accurrent2.h:149
i2c_master_t i2c
Definition accurrent2.h:146
accurrent2_drv_t drv_sel
Definition accurrent2.h:150
uint8_t slave_address
Definition accurrent2.h:148
analog_in_t adc
Definition accurrent2.h:145